
interface FlyBehavior{
    public void fly();
}
interface QuackBehavior{
    public void quack();
}
class FlyWithWings implements FlyBehavior{
    @Override
    public void fly() {
        System.out.println("使用翅膀飞行！");
    }
}
class FlyNoWay implements FlyBehavior{
    @Override
    public void fly() {
        System.out.println("不能飞行！");
    }
}
class Quack implements QuackBehavior{
    @Override
    public void quack() {
        System.out.println("发出\'嘎嘎\'声！");
    }   
}
class Squeak implements QuackBehavior{
    @Override
    public void quack() {
        System.out.println("发出空气与橡皮摩擦声！");
    }   
}
class QuackNoWay implements QuackBehavior{

    @Override
    public void quack() {
        System.out.println("不能发声！");
    }
    
}
abstract class Duck{
    protected FlyBehavior flyBehavior;
    protected QuackBehavior quackBehavior;
    public void fly(){
        this.flyBehavior.fly();
    }
    public void quack(){
        this.quackBehavior.quack();
    }
    public abstract void display();
}
class RubberDuck extends Duck{

    public RubberDuck() {
        this.flyBehavior=new FlyNoWay();
        this.quackBehavior=new Squeak();
    }
    
    @Override
    public void display() {
        System.out.println("橡皮鸭的颜色：黑白橡皮颜色");
    }
}
class MallardDuck extends Duck {
    public MallardDuck() {
        this.flyBehavior = new FlyWithWings();
        this.quackBehavior = new Quack();
    }
    @Override
    public void display() {
        System.out.println("灰鸭的颜色：灰色羽毛");
    }
}
class RedHeadDuck extends Duck {
        public RedHeadDuck() {
        this.flyBehavior = new FlyWithWings();
        this.quackBehavior = new Quack();
    }
    @Override
    public void display() {
        System.out.println("红头鸭的颜色：灰色羽毛、头部红色");
    }
}
class CottonDuck extends Duck {
        public CottonDuck() {
        this.flyBehavior = new FlyNoWay();
        this.quackBehavior = new QuackNoWay();
    }
    @Override
    public void display() {
        System.out.println("棉花鸭的颜色：白色");
    }
}
public class Main2007 {
    public static void showDuckInfo(Duck duck){
        duck.fly();
        duck.quack();
        duck.display();
    }
    public static void main(String[] args){
        
        System.out.println("------灰鸭------");
        showDuckInfo(new MallardDuck());
        System.out.println("------红头鸭------");
        showDuckInfo(new RedHeadDuck());
        System.out.println("------棉花鸭------");
        showDuckInfo(new CottonDuck());
        System.out.println("------橡皮鸭------");
        showDuckInfo(new RubberDuck());//Duck duck=new RubberDuck();
    }
}
